﻿using ICSharpCode.AvalonEdit;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;

namespace ICSharpCode.CodeCompletion
{
    //This file contains the custom dependency properties for the CodeTextEditor
    public partial class CodeTextEditor
    {
        /// <summary>
        /// Sets the CSharpCompletion implemetation
        /// </summary>
        public CSharpCompletion CodeCompletion
        {
            get { return (CSharpCompletion)GetValue(CodeCompletionProperty); }
            set { SetValue(CodeCompletionProperty, value); }
        }

        /// <summary>
        /// Sets the CSharpCompletion implemetation
        /// </summary>
        public static readonly DependencyProperty CodeCompletionProperty =
            DependencyProperty.Register("CodeCompletion", typeof(CSharpCompletion), typeof(CodeTextEditor), new PropertyMetadata(OnCodeCompletionChanged));

        static void OnCodeCompletionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CodeTextEditor editor = d as CodeTextEditor;
            if (editor != null)
            {
                editor.Completion = e.NewValue as CSharpCompletion;
            }
        }

        /// <summary>
        /// Sets the full name of the file opened.
        /// </summary>
        public string FullName
        {
            get { return (string)GetValue(FullNameProperty); }
            set { SetValue(FullNameProperty, value); }
        }

        /// <summary>
        /// Sets the full name of the file opened.
        /// Hill open the file in the editor.
        /// </summary>
        public static readonly DependencyProperty FullNameProperty =
            DependencyProperty.Register("FullName", typeof(string), typeof(CodeTextEditor), new PropertyMetadata(OnFullNameChanged));

        static void OnFullNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CodeTextEditor editor = d as CodeTextEditor;
            if (editor != null)
            {
                if (File.Exists(editor.FullName))
                    editor.OpenFile(editor.FullName);
            }
        }

        public TextEditorOptions CodeEditorOptions
        {
            get { return (TextEditorOptions)GetValue(CodeEditorOptionsProperty); }
            set { SetValue(CodeEditorOptionsProperty, value); }
        }

        public static readonly DependencyProperty CodeEditorOptionsProperty =
            DependencyProperty.Register("CodeEditorOptions", typeof(TextEditorOptions), typeof(CodeTextEditor), new PropertyMetadata(OnCodeEditorOptionsChanged));

        static void OnCodeEditorOptionsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CodeTextEditor editor = d as CodeTextEditor;
            if (editor != null)
            {
                editor.Options = editor.CodeEditorOptions;
            }
        }
    }
}
